package com.ncu702.backend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ncu702.backend.mapper.CommentMapper;
import com.ncu702.backend.model.entity.Comment;
import com.ncu702.backend.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {


    @Resource
    private CommentMapper commentMapper;

    @Override
    public ArrayList<Comment> getAll() {
       return (ArrayList<Comment>) commentMapper.selectList(null);
    }

    @Override
    public ArrayList<Comment> getAllArticleByArticleId(String articleId) {
        //默认的是主键
        return commentMapper.getAllCommentByArticleId(articleId);

    }

    @Override
    public boolean addComment(Comment comment) {
        return commentMapper.insert(comment)>0;
    }

    @Override
    public boolean deleteCommentByCid(String cid) {

        Map<String,Object> map=new HashMap<>();
        map.put("cid",cid);
        return commentMapper.deleteByMap(map)>0;
    }
}
